package com.tbit.main.service.impl;

import com.tbit.main.constant.MapConstant;
import com.tbit.main.constant.SysConstant;
import com.tbit.main.constant.enums.ParkPointType;
import com.tbit.main.h2.pojo.ParkPoint;
import com.tbit.main.pojo.*;
import com.tbit.common.entity.GPS.CarHistory;
import com.tbit.main.pojo.VO.UpKeepRespVO;
import com.tbit.main.service.CalibrateService;
import com.tbit.main.util.GeoUtil;
import com.tbit.main.util.calibrate.GpsCorrect;
import com.tbit.main.util.calibrate.GpsReverseCorrect;
import org.springframework.stereotype.Service;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@Service("calibrateService")
public class CalibrateServiceImpl implements CalibrateService {
    /**
     * 经纬度格式化
     */
    private DecimalFormat df = new DecimalFormat("#.######");

    @Override
    public void calibrateOffSet(TerPosition terPosition, int mapType) {
        double lng = terPosition.getLon();
        double lat = terPosition.getLat();

        Point p = calibrateOffSet(lng, lat, mapType);
        terPosition.setLonC(Double.parseDouble(df.format(p.getX())));
        terPosition.setLatC(Double.parseDouble(df.format(p.getY())));
    }

    @Override
    public void calibrateOffSet(PowerChangeLogExpand terPosition, int mapType) {
        double lng = terPosition.getLon();
        double lat = terPosition.getLat();

        Point p = calibrateOffSet(lng, lat, mapType);
        terPosition.setLonC(Double.parseDouble(df.format(p.getX())));
        terPosition.setLatC(Double.parseDouble(df.format(p.getY())));
    }

    @Override
    public void calibrateOffSet(WorkOrder workOrder, int mapType) {
        if (workOrder.getLon() != null && workOrder.getLat() != null) {
            double lng = workOrder.getLonC();
            double lat = workOrder.getLatC();
            Point p = calibrateOffSet(lng, lat, mapType);
            workOrder.setLonC(Double.parseDouble(df.format(p.getX())));
            workOrder.setLatC(Double.parseDouble(df.format(p.getY())));
        }
    }

    @Override
    public void calibrateOffSet(List<TerPosition> terPositions, int mapType) {
        for (int i = 0; i < terPositions.size(); i++) {
            TerPosition terPosition = terPositions.get(i);
            double lng = terPosition.getLon();
            double lat = terPosition.getLat();

            Point p = calibrateOffSet(lng, lat, mapType);
            terPosition.setLonC(Double.parseDouble(df.format(p.getX())));
            terPosition.setLatC(Double.parseDouble(df.format(p.getY())));
        }
    }

    @Override
    public void calibrateUserWork(List<AccountUserWork> accountUserWorkLogs, int mapType) {
        for (int i = 0; i < accountUserWorkLogs.size(); i++) {
            AccountUserWork accountUserWork = accountUserWorkLogs.get(i);
            double startLon = accountUserWork.getStartLon();
            double startLat = accountUserWork.getStartLat();
            double endLon = accountUserWork.getEndLon();
            double endLat = accountUserWork.getEndLat();

            Point start = calibrateOffSet(startLon, startLat, mapType);
            Point end = calibrateOffSet(endLon, endLat, mapType);
            accountUserWork.setStartLonC(Double.parseDouble(df.format(start.getX())));
            accountUserWork.setStartLatC(Double.parseDouble(df.format(start.getY())));
            accountUserWork.setEndLonC(Double.parseDouble(df.format(end.getX())));
            accountUserWork.setEndLatC(Double.parseDouble(df.format(end.getY())));
        }
    }

    @Override
    public void calTerUserWork(AccountUserWork accountUserWork, Integer oriMapType, Integer targetMapType) {

        if (accountUserWork.getEndLat() != null) {
            /*校准经纬度为原始经纬度*/
            Point point = new Point(accountUserWork.getEndLon(), accountUserWork.getEndLat());
            point = commonCalibrate(point, oriMapType, targetMapType);
            if (point != null) {
                accountUserWork.setEndLonC(point.getX());
                accountUserWork.setEndLatC(point.getY());
            }
        } else {
            /*校准经纬度为原始经纬度*/
            Point point = new Point(accountUserWork.getStartLon(), accountUserWork.getStartLat());
            point = commonCalibrate(point, oriMapType, targetMapType);
            if (point != null) {
                accountUserWork.setStartLonC(point.getX());
                accountUserWork.setStartLatC(point.getY());
            }
        }

    }


    /**
     * 获取校准点
     */
    public Point calibrateOffSet(double lo, double la, int mapType) {
        Point point = new Point(lo, la);
        if (MapConstant.MAP_BAIDU == mapType) {
            double[] latlng = GpsCorrect.oriToBaidu(la, lo);
            point.setX(latlng[1]);
            point.setY(latlng[0]);
        } else if (MapConstant.MAP_GOOGLE == mapType) {
            double[] latlng = GpsCorrect.oriToGoogle(la, lo);
            point.setX(latlng[1]);
            point.setY(latlng[0]);
        }

        return point;
    }

    /**
     * 获取逆向校准点
     */
    public Point calibrateRecerseOffSet(double lo, double la, int mapType) {
        Point point = new Point(lo, la);
        if (MapConstant.MAP_BAIDU == mapType) {
            double[] latlng = GpsReverseCorrect.baiduToOri(la, lo);
            point.setX(latlng[1]);
            point.setY(latlng[0]);
        } else if (MapConstant.MAP_GOOGLE == mapType) {
            double[] latlng = GpsReverseCorrect.googleToOri(la, lo);
            point.setX(latlng[1]);
            point.setY(latlng[0]);
        }

        return point;
    }

    @Override
    public void celibrateParkPoint(List<ParkPoint> parkPoints, int mapType) {
        for (int i = 0; i < parkPoints.size(); i++) {
            ParkPoint parkPoint = parkPoints.get(i);
            double lng = parkPoint.getLo();
            double lat = parkPoint.getLa();

            Point p = calibrateOffSet(lng, lat, mapType);
            parkPoint.setLoC(Double.parseDouble(df.format(p.getX())));
            parkPoint.setLaC(Double.parseDouble(df.format(p.getY())));
        }
    }

    @Override
    public void celibrateHotSite(List<HotIntelligentSite> hotIntelligentSites, int mapType) {

        for (int i = 0; i < hotIntelligentSites.size(); i++) {

            List<Point> points = GeoUtil.getPoints(hotIntelligentSites.get(i).getPoints());
            List<Point> pointCs = new ArrayList<Point>();
            for (Point point : points) {
                pointCs.add(commonCalibrate(point, SysConstant.ORIGINAL, mapType));
            }
            hotIntelligentSites.get(i).setPoints(GeoUtil.getPointToString(pointCs));

            List<Point> pointsR = GeoUtil.getPoints(hotIntelligentSites.get(i).getRecommendRange());
            List<Point> pointCsR = new ArrayList<Point>();
            for (Point point : pointsR) {
                pointCsR.add(commonCalibrate(point, SysConstant.ORIGINAL, mapType));
            }
            hotIntelligentSites.get(i).setRecommendRange(GeoUtil.getPointToString(pointCsR));

            HotIntelligentSite hotIntelligentSite = hotIntelligentSites.get(i);
            double lng = hotIntelligentSite.getLoC();
            double lat = hotIntelligentSite.getLaC();

            Point p = calibrateOffSet(lng, lat, mapType);
            hotIntelligentSite.setLoC(Double.parseDouble(df.format(p.getX())));
            hotIntelligentSite.setLaC(Double.parseDouble(df.format(p.getY())));
        }
    }

    @Override
    public void celibrateParkPointOne(ParkPoint parkPoint, int mapType) {
        double lng = parkPoint.getLo();
        double lat = parkPoint.getLa();
        Point p = calibrateOffSet(lng, lat, mapType);
        parkPoint.setLoC(Double.parseDouble(df.format(p.getX())));
        parkPoint.setLaC(Double.parseDouble(df.format(p.getY())));
    }

    @Override
    public void calibrateChargeHouse(List<ChargeHouse> chargeHouses, int mapType) {
        for (int i = 0; i < chargeHouses.size(); i++) {
            ChargeHouse chargeHouse = chargeHouses.get(i);
            double lng = chargeHouse.getLo();
            double lat = chargeHouse.getLa();

            Point p = calibrateOffSet(lng, lat, mapType);
            chargeHouse.setLoC(Double.parseDouble(df.format(p.getX())));
            chargeHouse.setLaC(Double.parseDouble(df.format(p.getY())));
        }
    }

    @Override
    public void calibrateWareHouse(List<Warehouse> warehouses, int mapType) {
        for (int i = 0; i < warehouses.size(); i++) {
            Warehouse warehouse = warehouses.get(i);
            double lng = warehouse.getLo();
            double lat = warehouse.getLa();

            Point p = calibrateOffSet(lng, lat, mapType);
            warehouse.setLoC(Double.parseDouble(df.format(p.getX())));
            warehouse.setLaC(Double.parseDouble(df.format(p.getY())));
        }
    }

    @Override
    public void calibrateWareHouseSin(Warehouse warehouse, int mapType) {
            double lng = warehouse.getLo();
            double lat = warehouse.getLa();
            Point p = calibrateOffSet(lng, lat, mapType);
            warehouse.setLoC(Double.parseDouble(df.format(p.getX())));
            warehouse.setLaC(Double.parseDouble(df.format(p.getY())));

    }

    @Override
    public void calibrateDetentionArea(DetentionArea detentionArea, int mapType) {
        double lng = detentionArea.getLo();
        double lat = detentionArea.getLa();
        Point p = calibrateOffSet(lng, lat, mapType);
        detentionArea.setLoC(Double.parseDouble(df.format(p.getX())));
        detentionArea.setLaC(Double.parseDouble(df.format(p.getY())));

    }


    /**
     * 经纬度校准
     */
    public Point calibrate(Point point, Integer mapType) {
        Point cP = calibrateOffSet(point.getX(), point.getY(), mapType);
        return new Point(Double.parseDouble(df.format(cP.getX())), Double.parseDouble(df.format(cP.getY())));
    }

    /**
     * 百度坐标转原始坐标
     */
    public Point baiduToOrigial(Point point) {
        Point bP = calibrateRecerseOffSet(point.getX(), point.getY(), SysConstant.BAIDU);
        return new Point(Double.parseDouble(df.format(bP.getX())), Double.parseDouble(df.format(bP.getY())));
    }

    /**
     * 谷歌坐标转原始坐标
     */
    public Point googleToOrigial(Point point) {
        Point bP = calibrateRecerseOffSet(point.getX(), point.getY(), SysConstant.GOOGLE);
        return new Point(Double.parseDouble(df.format(bP.getX())), Double.parseDouble(df.format(bP.getY())));
    }

    @Override
    public Point commonCalibrate(Point point, Integer from, Integer to) {
        if (from == SysConstant.ORIGINAL && to == SysConstant.BAIDU) {
            /*原始到百度*/
            point = calibrate(point, SysConstant.BAIDU);
        } else if (from == SysConstant.ORIGINAL && to == SysConstant.GOOGLE) {
            /*原始到谷歌*/
            point = calibrate(point, SysConstant.GOOGLE);
        } else if (from == SysConstant.BAIDU && to == SysConstant.ORIGINAL) {
            /*百度到原始*/
            point = baiduToOrigial(point);
        } else if (from == SysConstant.GOOGLE && to == SysConstant.ORIGINAL) {
            /*谷歌到原始*/
            point = googleToOrigial(point);
        }
        return point;
    }


    @Override
    public void calParkPoint(ParkPoint parkPoint, Integer oriMapType, Integer targetMapType) {
        if (ParkPointType.PARKPOINT_POLYGON_TYPE.getType().equals(parkPoint.getParkPointType())) {//多边形电子围栏
            List<Point> points = GeoUtil.getPoints(parkPoint.getPoints());
            List<Point> pointCs = new ArrayList<Point>();
            for (Point point : points) {
                pointCs.add(commonCalibrate(point, oriMapType, targetMapType));
            }
            parkPoint.setPoints(GeoUtil.getPointToString(pointCs));
        }

        /*校准经纬度为原始经纬度*/
        Point point = new Point(parkPoint.getLo(), parkPoint.getLa());
        point = commonCalibrate(point, oriMapType, targetMapType);
        if (point != null) {
            parkPoint.setLo(point.getX());
            parkPoint.setLa(point.getY());
        }
    }

    @Override
    public void calDetentionArea(DetentionArea detentionArea, Integer oriMapType,
                                 Integer targetMapType) {
        if (ParkPointType.PARKPOINT_POLYGON_TYPE.getType().equals(detentionArea.getType())) {//多边形电子围栏
            List<Point> points = GeoUtil.getPoints(detentionArea.getPoints());
            List<Point> pointCs = new ArrayList<Point>();
            for (Point point : points) {
                pointCs.add(commonCalibrate(point, oriMapType, targetMapType));
            }
            detentionArea.setPoints(GeoUtil.getPointToString(pointCs));
        }

        /*校准经纬度为原始经纬度*/
        Point point = new Point(detentionArea.getLo(), detentionArea.getLa());
        point = commonCalibrate(point, oriMapType, targetMapType);
        if (point != null) {
            detentionArea.setLo(point.getX());
            detentionArea.setLa(point.getY());
        }
    }

    @Override
    public void calChargeHouse(ChargeHouse chargeHouse, Integer oriMapType, Integer targetMapType) {
        /*校准经纬度为原始经纬度*/
        Point point = new Point(chargeHouse.getLo(), chargeHouse.getLa());
        point = commonCalibrate(point, oriMapType, targetMapType);
        if (point != null) {
            chargeHouse.setLo(point.getX());
            chargeHouse.setLa(point.getY());
        }
    }

    @Override
    public void calWarehouse(Warehouse warehouse, Integer oriMapType, Integer targetMapType) {
        /*校准经纬度为原始经纬度*/
        Point point = new Point(warehouse.getLo(), warehouse.getLa());
        point = commonCalibrate(point, oriMapType, targetMapType);
        if (point != null) {
            warehouse.setLo(point.getX());
            warehouse.setLa(point.getY());
        }
    }

    @Override
    public void calGeo(Geo geo, Integer oriMapType, Integer targetMapType) {
        List<Point> points = GeoUtil.getPoints(geo.getPoints());
        List<Point> pointCs = new ArrayList<Point>();
        for (Point point : points) {
            pointCs.add(commonCalibrate(point, oriMapType, targetMapType));
        }

        geo.setPointsC(GeoUtil.getPointToString(pointCs));
    }

    @Override
    public void celibrateGeoreGion(List<GeoreGion> georeGions, int oriMapType, int mapType) {
        for (GeoreGion georeGion : georeGions) {
            List<Point> points = GeoUtil.getPoints(georeGion.getPoints());
            List<Point> pointCs = new ArrayList<Point>();
            for (Point point : points) {
                pointCs.add(commonCalibrate(point, oriMapType, mapType));
            }
            georeGion.setPoints(GeoUtil.getPointToString(pointCs));
            georeGion.setPointsC(GeoUtil.getPointToString(pointCs));
        }

        for (int i = 0; i < georeGions.size(); i++) {
            GeoreGion georeGion = georeGions.get(i);
            double lng = georeGion.getCenterLon();
            double lat = georeGion.getCenterLat();

            Point p = calibrateOffSet(lng, lat, mapType);
            georeGion.setCenterLon(Double.parseDouble(df.format(p.getX())));
            georeGion.setCenterLat(Double.parseDouble(df.format(p.getY())));
        }
    }

    /*@Override
    public void calGeoreGion(GeoreGion georeGion, Integer oriMapType, Integer targetMapType) {
        List<Point> points= GeoUtil.getPoints(georeGion.getPoints());
        List<Point> pointCs=new ArrayList<Point>();
        for(Point point:points){
            pointCs.add(commonCalibrate(point,oriMapType,targetMapType));
        }

        georeGion.setPointsC(GeoUtil.getPointToString(pointCs));
    }*/
    @Override
    public void calGeoreGion(GeoreGion georeGion, Integer oriMapType, Integer targetMapType) {

        List<Point> points = GeoUtil.getPoints(georeGion.getPoints());
        List<Point> pointCs = new ArrayList<Point>();
        for (Point point : points) {
            pointCs.add(commonCalibrate(point, oriMapType, targetMapType));
        }
        georeGion.setPointsC(GeoUtil.getPointToString(pointCs));

        /*校准经纬度为原始经纬度*/
        Point point = new Point(georeGion.getCenterLon(), georeGion.getCenterLat());
        point = commonCalibrate(point, oriMapType, targetMapType);
        if (point != null) {
            georeGion.setCenterLon(point.getX());
            georeGion.setCenterLat(point.getY());
        }
    }

    @Override
    public <T> void calPolygon(T t, Integer oriMapType, Integer targetMapType) {
        if (t instanceof ParkPointVert) {
            ParkPointVert parkPointVert = (ParkPointVert) t;
            List<Point> points = GeoUtil.getPoints(parkPointVert.getPoints());
            List<Point> pointCs = new ArrayList<Point>();
            for (Point point : points) {
                pointCs.add(commonCalibrate(point, oriMapType, targetMapType));
            }
            if (oriMapType.equals(MapConstant.MAP_ORI)) {
                //从数据库获取
                parkPointVert.setPointsC(GeoUtil.getPointToString(pointCs));
            } else {
                //保存到数据库
                parkPointVert.setPoints(GeoUtil.getPointToString(pointCs));
            }
        } else if (t instanceof GeoreGion) {
            GeoreGion parkPointVert = (GeoreGion) t;
            List<Point> points = GeoUtil.getPoints(parkPointVert.getPoints());
            List<Point> pointCs = new ArrayList<Point>();
            for (Point point : points) {
                pointCs.add(commonCalibrate(point, oriMapType, targetMapType));
            }
            if (oriMapType.equals(MapConstant.MAP_ORI)) {
                //从数据库获取
                parkPointVert.setPoints(GeoUtil.getPointToString(pointCs));
            } else {
                //保存到数据库
                parkPointVert.setPoints(GeoUtil.getPointToString(pointCs));
            }
        }
    }

    @Override
    public void calParkPointVert(ParkPointVert parkPointVert, Integer oriMapType, Integer targetMapType) {
        List<Point> points = GeoUtil.getPoints(parkPointVert.getPoints());
        List<Point> pointCs = new ArrayList<Point>();
        for (Point point : points) {
            pointCs.add(commonCalibrate(point, oriMapType, targetMapType));
        }
        if (oriMapType.equals(MapConstant.MAP_ORI)) {
            //从数据库获取
            parkPointVert.setPointsC(GeoUtil.getPointToString(pointCs));
        } else {
            //保存到数据库
            parkPointVert.setPoints(GeoUtil.getPointToString(pointCs));
        }
    }

    @Override
    public void calParkPointVertList(List<ParkPointVert> parkPointVertList, Integer oriMapType, Integer targetMapType) {
        for (ParkPointVert parkPointVert : parkPointVertList) {
            List<Point> points = GeoUtil.getPoints(parkPointVert.getPoints());
            List<Point> pointCs = new ArrayList<Point>();
            for (Point point : points) {
                pointCs.add(commonCalibrate(point, oriMapType, targetMapType));
            }
            if (oriMapType.equals(MapConstant.MAP_ORI)) {
                //从数据库获取
                parkPointVert.setPointsC(GeoUtil.getPointToString(pointCs));
            } else {
                //保存到数据库
                parkPointVert.setPoints(GeoUtil.getPointToString(pointCs));
            }
        }
    }

    @Override
    public void celibrateMachineStatus(List<MachineStatus> machineStatuses, int mapType) {
        for (MachineStatus ms : machineStatuses) {
            ms.setLon(Double.parseDouble(df.format(ms.getLon())));
            ms.setLat(Double.parseDouble(df.format(ms.getLat())));
            Point point = new Point(ms.getLon(), ms.getLat());
            point = commonCalibrate(point, MapConstant.MAP_ORI, mapType);
            ms.setLonC(point.getX());
            ms.setLatC(point.getY());
        }
    }

    @Override
    public void celibrateWorkOrderFinish(List<WorkOrderFinishing> workOrderFinishings, int mapType) {
        for (WorkOrderFinishing ms : workOrderFinishings) {
            if (ms.getLatC() != null && ms.getLonC() != null) {
                ms.setLon(Double.parseDouble(df.format(ms.getLonC())));
                ms.setLat(Double.parseDouble(df.format(ms.getLatC())));
                Point point = new Point(ms.getLon(), ms.getLat());
                point = commonCalibrate(point, MapConstant.MAP_ORI, mapType);
                ms.setLonC(point.getX());
                ms.setLatC(point.getY());
            }
        }
    }

    @Override
    public void celibrateWorkOrder(List<WorkOrder> workOrders, int mapType) {
        for (WorkOrder ms : workOrders) {
            if (ms.getLat() != null && ms.getLon() != null) {
                ms.setLon(Double.parseDouble(df.format(ms.getLonC())));
                ms.setLat(Double.parseDouble(df.format(ms.getLatC())));
                Point point = new Point(ms.getLon(), ms.getLat());
                point = commonCalibrate(point, MapConstant.MAP_ORI, mapType);
                ms.setLonC(point.getX());
                ms.setLatC(point.getY());
            }
        }
    }

    @Override
    public void celibrateMachineStatusBorrow(List<MachineStatusBorrow> machineStatusBorrows, int mapType) {
        for (MachineStatusBorrow ms : machineStatusBorrows) {
            ms.setLon(Double.parseDouble(df.format(ms.getLon())));
            ms.setLat(Double.parseDouble(df.format(ms.getLat())));
            Point point = new Point(ms.getLon(), ms.getLat());
            point = commonCalibrate(point, MapConstant.MAP_ORI, mapType);
            ms.setLonC(point.getX());
            ms.setLatC(point.getY());
        }
    }

    @Override
    public void calMoveLog(MoveLog moveLog, Integer oriMapType, Integer targetMapType) {
        /*开始经纬度*/
        Point pointStart = new Point(moveLog.getStartLon(), moveLog.getStartLat());
        pointStart = commonCalibrate(pointStart, oriMapType, targetMapType);
        if (pointStart != null) {
            moveLog.setStartLonC(pointStart.getX());
            moveLog.setStartLatC(pointStart.getY());
        }

        /*结束经纬度*/
        if (moveLog.getEndLon() != null && moveLog.getEndLat() != null) {
            Point pointEnd = new Point(moveLog.getEndLon(), moveLog.getEndLat());
            pointEnd = commonCalibrate(pointEnd, oriMapType, targetMapType);
            if (pointStart != null) {
                moveLog.setEndLonC(pointEnd.getX());
                moveLog.setEndLatC(pointEnd.getY());
            }
        }
    }

    @Override
    public void calProhibitArea(ProhibitArea prohibitArea, Integer oriMapType, Integer targetMapType) {
        List<Point> points = GeoUtil.getPoints(prohibitArea.getPoints());
        List<Point> pointCs = new ArrayList<Point>();
        for (Point point : points) {
            pointCs.add(commonCalibrate(point, oriMapType, targetMapType));
        }
        prohibitArea.setPoints(GeoUtil.getPointToString(pointCs));

        /*校准经纬度为原始经纬度*/
        Point point = new Point(prohibitArea.getLo(), prohibitArea.getLa());
        point = commonCalibrate(point, oriMapType, targetMapType);
        if (point != null) {
            prohibitArea.setLo(point.getX());
            prohibitArea.setLa(point.getY());
        }
    }

    @Override
    public void celibrateProhibitArea(List<ProhibitArea> prohibitAreas, int mapType) {
        for (int i = 0; i < prohibitAreas.size(); i++) {
            ProhibitArea prohibitArea = prohibitAreas.get(i);
            double lng = prohibitArea.getLo();
            double lat = prohibitArea.getLa();

            /**中心点校准*/
            Point p = calibrateOffSet(lng, lat, mapType);
            prohibitArea.setLoC(Double.parseDouble(df.format(p.getX())));
            prohibitArea.setLaC(Double.parseDouble(df.format(p.getY())));

            /**校准点集合*/
            List<Point> points = GeoUtil.getPoints(prohibitArea.getPoints());
            List<Point> pointCs = new ArrayList<Point>();
            for (Point point : points) {
                pointCs.add(commonCalibrate(point, SysConstant.ORIGINAL, mapType));
            }
            prohibitArea.setPointsC(GeoUtil.getPointToString(pointCs));
        }
    }

    @Override
    public void calibrateMachineLastUseLog(List<MachineLastUseLog> machineLastUseLogs, int mapType) {
        for (int i = 0; i < machineLastUseLogs.size(); i++) {
            MachineLastUseLog machineLastUseLog = machineLastUseLogs.get(i);
            double lng = machineLastUseLog.getLo();
            double lat = machineLastUseLog.getLa();

            Point p = calibrateOffSet(lng, lat, mapType);
            machineLastUseLog.setLo(Double.parseDouble(df.format(p.getX())));
            machineLastUseLog.setLa(Double.parseDouble(df.format(p.getY())));
        }
    }

    @Override
    public void calMachineLastUseLog(MachineLastUseLog machineLastUseLog, Integer oriMapType, Integer targetMapType) {
        /*校准经纬度为原始经纬度*/
        Point point = new Point(machineLastUseLog.getLo(), machineLastUseLog.getLa());
        point = commonCalibrate(point, oriMapType, targetMapType);
        if (point != null) {
            machineLastUseLog.setLo(point.getX());
            machineLastUseLog.setLa(point.getY());
        }
    }

    @Override
    public void calibrateLastPos(AccountUserLastPos accountUserLastPos, int mapType) {
        double lng = accountUserLastPos.getLon();
        double lat = accountUserLastPos.getLat();

        Point p = calibrateOffSet(lng, lat, mapType);
        accountUserLastPos.setLonC(Double.parseDouble(df.format(p.getX())));
        accountUserLastPos.setLatC(Double.parseDouble(df.format(p.getY())));
    }

    @Override
    public void calibrateLastPosS(List<AccountUserLastPos> accountUserLastPos, int mapType) {
        for (AccountUserLastPos accountUserLastPos1 : accountUserLastPos) {
            calibrateLastPos(accountUserLastPos1, mapType);
        }
    }

    @Override
    public void calibrateGPSLastPosS(List<CarHistory> carHistories, int mapType) {
        for (CarHistory carHistory : carHistories) {
            double lng = carHistory.getLon();
            double lat = carHistory.getLat();
            Point p = calibrateOffSet(lng, lat, mapType);
            carHistory.setLon_c(Double.parseDouble(df.format(p.getX())));
            carHistory.setLat_c(Double.parseDouble(df.format(p.getY())));
        }
    }

    @Override
    public void calibrateGPSLastPos(CarHistory carHistorie, int mapType) {
        double lng = carHistorie.getLon();
        double lat = carHistorie.getLat();
        Point p = calibrateOffSet(lng, lat, mapType);
        carHistorie.setLon_c(Double.parseDouble(df.format(p.getX())));
        carHistorie.setLat_c(Double.parseDouble(df.format(p.getY())));
    }


    @Override
    public void calTerPosition(TerPosition parkPoint, Integer oriMapType, Integer targetMapType) {
        /*校准经纬度为原始经纬度*/
        Point point = new Point(parkPoint.getLon(), parkPoint.getLat());
        point = commonCalibrate(point, oriMapType, targetMapType);
        if (point != null) {
            parkPoint.setLonC(point.getX());
            parkPoint.setLatC(point.getY());
        }
    }

    @Override
    public void calibrateOffSetReturn(List<ReturnPosLog> terPositions, int mapType) {
        for (int i = 0; i < terPositions.size(); i++) {
            ReturnPosLog terPosition = terPositions.get(i);
            double lng = terPosition.getLon();
            double lat = terPosition.getLat();

            Point p = calibrateOffSet(lng, lat, mapType);
            terPosition.setLon(Double.parseDouble(df.format(p.getX())));
            terPosition.setLat(Double.parseDouble(df.format(p.getY())));
        }
    }

    @Override
    public void calibrateOffSetBorrow(List<BorrowPosLog> terPositions, int mapType) {
        for (int i = 0; i < terPositions.size(); i++) {
            BorrowPosLog terPosition = terPositions.get(i);
            double lng = terPosition.getLon();
            double lat = terPosition.getLat();

            Point p = calibrateOffSet(lng, lat, mapType);
            terPosition.setLon(Double.parseDouble(df.format(p.getX())));
            terPosition.setLat(Double.parseDouble(df.format(p.getY())));
        }
    }

    @Override
    public void calibrateOffSetReturnBikeMsgLog(List<ReturnBikeMsgLog> terPositions, int mapType) {
        for (int i = 0; i < terPositions.size(); i++) {
            ReturnBikeMsgLog terPosition = terPositions.get(i);
            double lng = terPosition.getLon();
            double lat = terPosition.getLat();

            Point p = calibrateOffSet(lng, lat, mapType);
            terPosition.setLonC(Double.parseDouble(df.format(p.getX())));
            terPosition.setLatC(Double.parseDouble(df.format(p.getY())));
        }
    }


    @Override
    public void calibrateMachined(Machine byUseCodeMachine, Integer mapType) {
        double lng = byUseCodeMachine.getLon();
        double lat = byUseCodeMachine.getLat();
        Point p = calibrateOffSet(lng, lat, mapType);
        byUseCodeMachine.setLoC(Double.parseDouble(df.format(p.getX())));
        byUseCodeMachine.setLaC(Double.parseDouble(df.format(p.getY())));

    }

    @Override
    public void calibrateUpKeeps(List<UpKeepRespVO> list, Integer mapType) {
        for (UpKeepRespVO upKeep : list) {
            if (Objects.nonNull(upKeep.getLon()) && Objects.nonNull(upKeep.getLat())) {
                Point point = new Point(upKeep.getLon(), upKeep.getLat());
                point = commonCalibrate(point, MapConstant.MAP_ORI, mapType);
                upKeep.setLonC(point.getX());
                upKeep.setLatC(point.getY());
            }
        }
    }
}